package cn.com.cetccst.sdk.modelbiz;

import static cn.com.cetccst.sdk.modelbase.ConstantsAPI.COMMAND_RECEIVE_PAYLOAD_MESSAGE;

import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;

import cn.com.cetccst.sdk.modelbase.BaseReq;
import cn.com.cetccst.sdk.modelbase.BaseResp;

/**
 * 消息中心处理
 */
public class ReceivePayloadMessage {
    public static final String TAG = "SendCloudMessage";

    public static class Req extends BaseReq {

        public static final String SSAPI_RECEIVEPAYLOADMESSAGE_REQ_MESSAGE = "ssapi_receivepayloadmessage_req_message";
        public static final String SSAPI_RECEIVEPAYLOADMESSAGE_REQ_TIME = "ssapi_receivepayloadmessage_req_time";
        public String message;
        public long time;

        public Req() {
            this(COMMAND_RECEIVE_PAYLOAD_MESSAGE);
        }

        public Req(int commandId) {
            super(commandId);
        }

        public Req(Bundle bundle) {
            this();
            fromBundle(bundle);
        }

        public void fromBundle(Bundle bundle) {
            super.fromBundle(bundle);
            message = bundle.getString(SSAPI_RECEIVEPAYLOADMESSAGE_REQ_MESSAGE);
            time = bundle.getLong(SSAPI_RECEIVEPAYLOADMESSAGE_REQ_TIME);
        }

        public void toBundle(Bundle bundle) {
            super.toBundle(bundle);
            bundle.putString(SSAPI_RECEIVEPAYLOADMESSAGE_REQ_MESSAGE, message);
            bundle.putLong(SSAPI_RECEIVEPAYLOADMESSAGE_REQ_TIME, time);
        }

        public boolean checkArgs() {
            if (TextUtils.isEmpty(message) || time < 0) {
                Log.e(TAG, "checkArgs fail ,message is null, or time < 0, enterpriseId < 0.");
                return false;
            }
            return true;
        }

        @Override
        public String toString() {
            return "Req{" +
                    "message='" + message + '\'' +
                    ", time=" + time +
                    ", type=" + type +
                    ", transaction='" + transaction + '\'' +
                    ", sdkVersion=" + sdkVersion +
                    ", appKey='" + appKey + '\'' +
                    '}';
        }
    }

    public static class Resp extends BaseResp {

        public Resp() {
            this(COMMAND_RECEIVE_PAYLOAD_MESSAGE);
        }

        public Resp(int commandId) {
            super(commandId);
        }

        public Resp(Bundle bundle) {
            this();
            this.fromBundle(bundle);
        }
    }
}
